package dataset;

import java.util.Map;


/**
 * This class specifies a command that enables users undo changes
 * that they have made to the view. When this command filters x 
 * values above a certain, threshold value it stores what it filtered
 * and logs its actions with a datalogger. Calling the DataLogger's
 * undo() method will automatically undo the initial actions of this
 * class. 
 * 
 * @author Paul Dannenberg
 * 
 * @param <T>
 * @param <S>
 */


//TODO Create superclass for this command to allow FilterXCommand to be merged
// with the as of yet unimplemented FilterYCommand?

public class FilterXCommand<T extends Comparable<T>, S extends Comparable<S>>
        implements IResettableCommand<T, S> {

    private static final String NAME = "xfilter";
    private DataLogger<T, S> myDataLogger;
    private Map<T, S> myFiltered;
    private T myLowerBound;
    private T myUpperBound;

    /**
     * 
     * @param lowerBound Lowest acceptable value
     * @param upperBound Largest acceptable value
     * @param The datalogger where this commmand's
     * actions should be stored.
     */
    public FilterXCommand (T lowerBound, T upperBound, DataLogger<T, S> logger) {
        myLowerBound = lowerBound;
        myUpperBound = upperBound;
        myDataLogger = logger;
    }

    @Override
    public void execute (DataSet<T, S> toExecuteOn) {
        myFiltered = toExecuteOn.filterX(myLowerBound, myUpperBound);
        myDataLogger.log(this, toExecuteOn);
    }

    @Override
    public String getName () {
        return NAME;
    }

    @Override
    public void reset (DataSet<T, S> toReset) {
        toReset.merge(myFiltered);
    }
}
